package com.yf.ma;

import java.nio.ByteBuffer;
import java.util.Scanner;

/**
 * 测试直接内存的占用与释放
 */
public class DirectBufferTest {
    private static final int SIZE = 1024 * 1024 * 1024; // 1GB
    public static void main(String[] args) {
        // 直接分配本地内存空间
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(SIZE);
        System.out.println("直接内存分配完毕，请求指示！");

        Scanner scanner = new Scanner(System.in);
        scanner.next();

        System.out.println("直接内存开始释放！");
        byteBuffer = null;
        System.gc();

        scanner.next();
    }
}
